# -*- coding: utf-8 -*-
#!/usr/bin/python

##copyright 2014 Sebastian Stetter
##This file is part of the Lemonade Small Business Suite project and released under GPL v2
##http://lemonade.sebastianstetter.de

########################################
#
#Choice functions for choice delegates to use in field_attributes of Object Admin
#field_attributes=dict(fieldname=dict(choice=preferred_phone_choice))
########################################
    

def prefered_phone_choices(customer):
    """customize this funtion to define which mechanisms should be shown vor which customer """
    choices = [ (contact_mechanism , contact_mechanism.mechanism) for contact_mechanism in ContactMechanism.query.filter_by(customer=customer)]
    filtered_choices = [choice for choice in choices if choice[1][0]==u'phone' or choice[1][0]==u'mobile']
    #choices[0] enthält das camelot.types.VirtualAddress was in der db gespeichert wird und choices[1] ein tuple im format (u'email:', u'1234567')
    #formatted for nicer display
    pretty_choices = [(choice[0], u"%s: %s (%s)" %(choice[1][0], choice[1][1], choice[0].type )) for choice in filtered_choices]
    return pretty_choices
    
def prefered_email_choices(customer):
    """customize this funtion to define which mechanisms should be shown vor which customer """
    choices = [ (contact_mechanism , contact_mechanism.mechanism) for contact_mechanism in ContactMechanism.query.filter_by(customer=customer)]
    filtered_choices = [choice for choice in choices if choice[1][0]==u'email' ]
    #choices[0] enthält das camelot.types.VirtualAddress was in der db gespeichert wird und choices[1] ein tuple im format (u'email:', u'1234567')
    pretty_choices = [(choice[0], u"%s: %s (%s)" %(choice[1][0], choice[1][1], choice[0].type )) for choice in filtered_choices]
    return pretty_choices
    
def prefered_website_choices(customer):
    """customize this funtion to define which mechanisms should be shown vor which customer """
    choices = [ (contact_mechanism , contact_mechanism.mechanism) for contact_mechanism in ContactMechanism.query.filter_by(customer=customer)]
    filtered_choices = [choice for choice in choices if choice[1][0]==u'web' ]
    #choices[0] enthält das camelot.types.VirtualAddress was in der db gespeichert wird und choices[1] ein tuple im format (u'email:', u'1234567')
    pretty_choices = [(choice[0], u"%s: %s (%s)" %(choice[1][0], choice[1][1], choice[0].type )) for choice in filtered_choices]
    return pretty_choices
    
def prefered_social_choices(customer):
    """customize this funtion to define which mechanisms should be shown vor which customer """
    choices = [ (contact_mechanism , contact_mechanism.mechanism) for contact_mechanism in ContactMechanism.query.filter_by(customer=customer)]
    filtered_choices = [choice for choice in choices if choice[1][0]==u'social' ]
    #choices[0] enthält das camelot.types.VirtualAddress was in der db gespeichert wird und choices[1] ein tuple im format (u'email:', u'1234567')
    pretty_choices = [(choice[0], u"%s: %s (%s)" %(choice[1][0], choice[1][1], choice[0].type )) for choice in filtered_choices]
    return pretty_choices
    
def customer_address_choices(customer):
    """customize this funtion to define which mechanisms should be shown vor which customer """
    addresses = [ address for address in Address.query.filter_by(customer=customer)]
    pretty_addresses = [(address, u"%s: %s, %s %s, %s"%(address.type,  address.street_box,  address.zip,  address.city,  address.country)) for address in addresses]
    print pretty_addresses
    return pretty_addresses
